package com.hao.tool.extra.simple;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.hao.tool.extra.cloud.module.ali.entity.AlCosDTO;

import java.io.File;
import java.io.FileNotFoundException;
import java.time.LocalDateTime;
import java.util.Scanner;

/**
 * 上传文件
 *
 * @author HaoZ on CMHK.gz
 * @date 2020-11-05 14:22
 */
public class FileUploadTool {

    public static void main(String[] args) throws FileNotFoundException {
        FileUploadTool aliFileUpload = new FileUploadTool();
        aliFileUpload.execute();
    }


    public void execute() throws FileNotFoundException {
        String logPath = "HaoSimpleTool" + File.separator + "fuLog.log";
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入：【本地文件或文件夹名】");
        String filePath = scan.next();
        File file = new File(filePath);
        if (!file.exists()) {
            System.out.println("文件不存在！！！");
        }

        AlCosDTO alCosDTO = new AlCosDTO();
        alCosDTO.setBucketName("ecip");
        alCosDTO.setCosPrefixUrl("http://e.lymtr.cn/");
        String yyyyMMdd = "fileupload"
                + "/" + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN);
        AliCosUploadUtil batchUploadUtil = new AliCosUploadUtil(filePath, logPath);
        batchUploadUtil.uploadDefDir(file, yyyyMMdd, alCosDTO, false);
    }


}
